<template>
	<div class="systemParameterPage">
		<div class="systemParameterPageBox">
			<div class="pageConfigBox">
				<div class="pageConfigBoxTitle">
					<div class="titleText">心跳配置</div>
				</div>
				<div class="pageConfigBoxContent">
					<div class="pageConfigBoxContentItem">
						<div class="form_text">心跳频率</div>
						<div class="form_item">
							<el-select v-model="heartbeatConfig.heartbeatFrequency" placeholder="请选择" @change="handleSelect_heartbeat">
								<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"> </el-option>
							</el-select>
						</div>
						<div class="form_hint">提示：更频繁的上报频率可以查看更实时的数据，但也会占用网络带宽</div>
					</div>
				</div>
			</div>
			<div class="pageConfigBox">
				<div class="pageConfigBoxTitle">
					<div class="titleText">请求配置</div>
				</div>
				<div class="pageConfigBoxContent">
					<div class="pageConfigBoxContentItem">
						<div class="form_text">请求频率</div>
						<div class="form_item">
							<el-select v-model="requestConfig.requestFrequency" placeholder="请选择" @change="handleSelect_request">
								<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"> </el-option>
							</el-select>
						</div>
						<div class="form_hint">提示：更频繁的上报频率可以查看更实时的数据，但也会占用网络带宽</div>
					</div>
				</div>
			</div>
			<div class="pageConfigBox">
				<div class="pageConfigBoxTitle">
					<div class="titleText">告警上报配置</div>
				</div>
				<div class="pageConfigBoxContent">
					<div class="pageConfigBoxContentItem">
						<div class="form_text">告警上报</div>
						<div class="form_item">
							<el-switch v-model="waringConfig.waringState" @change="handleSwitchWaring" active-color="#13ce66" inactive-color="#ff4949">
							</el-switch>
						</div>
						<div class="form_hint">提示：开启后方可收到安全终端的运维日志、告警信息等的上报。</div>
					</div>
					<div class="pageConfigBoxContentItem">
						<div class="form_text">发送频率</div>
						<div class="form_item">
							<el-select v-model="waringConfig.waringFrequency" placeholder="请选择" @change="handleSelect_waring">
								<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"> </el-option>
							</el-select>
						</div>
						<div class="form_hint">提示：更频繁的上报频率可以查看更实时的数据，但也会占用网络带宽</div>
					</div>
				</div>
			</div>
			<div class="pageConfigBox">
				<div class="pageConfigBoxTitle">
					<div class="titleText">审计上报配置</div>
				</div>
				<div class="pageConfigBoxContent">
					<div class="pageConfigBoxContentItem">
						<div class="form_text">审计上报</div>
						<div class="form_item">
							<el-switch v-model="auditConfig.auditState" @change="handleSwitchAudit" active-color="#13ce66" inactive-color="#ff4949">
							</el-switch>
						</div>
						<div class="form_hint">提示：开启后方可收到安全终端监控信息的上报</div>
					</div>
					<div class="pageConfigBoxContentItem">
						<div class="form_text">发送频率</div>
						<div class="form_item">
							<el-select v-model="auditConfig.auditFrequency" placeholder="请选择" @change="handleSelect_audit">
								<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"> </el-option>
							</el-select>
						</div>
						<div class="form_hint">提示：更频繁的上报频率可以查看更实时的数据，但也会占用网络带宽</div>
					</div>
				</div>
			</div>
			<div class="pageConfigBox">
				<div class="pageConfigBoxTitle">
					<div class="titleText">比较频率配置</div>
				</div>
				<div class="pageConfigBoxContent">
					<div class="pageConfigBoxContentItem">
						<div class="form_text">比较上报</div>
						<div class="form_item">
							<el-switch v-model="compareConfig.compareState" @change="handleSwitchCompare" active-color="#13ce66" inactive-color="#ff4949">
							</el-switch>
						</div>
						<div class="form_hint">提示：开启后方可收到安全终端监控信息的上报</div>
					</div>
					<div class="pageConfigBoxContentItem">
						<div class="form_text">发送频率</div>
						<div class="form_item">
							<el-select v-model="compareConfig.compareFrequency" placeholder="请选择" @change="handleSelect_compare">
								<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"> </el-option>
							</el-select>
						</div>
						<div class="form_hint">提示：更频繁的上报频率可以查看更实时的数据，但也会占用网络带宽</div>
					</div>
				</div>
			</div>
			<div class="pageConfigBox">
				<div class="pageConfigBoxTitle">
					<div class="titleText">终端监控配置</div>
				</div>
				<div class="pageConfigBoxContent">
					<div class="pageConfigBoxContentItem">
						<div class="form_text">监控上报</div>
						<div class="form_item">
							<el-switch
								v-model="terminalMonitoringConfig.terminalMonitoringState"
								@change="handleSwitchTerminalMonitoring"
								active-color="#13ce66"
								inactive-color="#ff4949"
							>
							</el-switch>
						</div>
						<div class="form_hint">提示：开启后方可收到安全终端监控信息的上报</div>
					</div>
					<div class="pageConfigBoxContentItem">
						<div class="form_text">发送频率</div>
						<div class="form_item">
							<el-select
								v-model="terminalMonitoringConfig.terminalMonitoringFrequency"
								placeholder="请选择"
								@change="handleSelect_terminalMonitoring"
							>
								<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"> </el-option>
							</el-select>
						</div>
						<div class="form_hint">提示：更频繁的上报频率可以查看更实时的数据，但也会占用网络带宽</div>
					</div>
				</div>
			</div>
			<div class="pageConfigBox">
				<div class="pageConfigBoxTitle">
					<div class="titleText">系统日志配置</div>
				</div>
				<div class="pageConfigBoxContent">
					<div class="pageConfigBoxContentItem">
						<div class="form_text">日志上报</div>
						<div class="form_item">
							<el-switch
								v-model="systemLogConfig.systemLogState"
								@change="handleSwitchSystemLog"
								active-color="#13ce66"
								inactive-color="#ff4949"
							>
							</el-switch>
						</div>
						<div class="form_hint">提示：开启后方可收到安全终端监控信息的上报</div>
					</div>
					<div class="pageConfigBoxContentItem">
						<div class="form_text">发送频率</div>
						<div class="form_item">
							<el-select v-model="systemLogConfig.systemLogFrequency" placeholder="请选择" @change="handleSelect_systemLog">
								<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"> </el-option>
							</el-select>
						</div>
						<div class="form_hint">提示：更频繁的上报频率可以查看更实时的数据，但也会占用网络带宽</div>
					</div>
				</div>
			</div>
			<div class="pageConfigBox">
				<div class="pageConfigBoxTitle">
					<div class="titleText">开关门配置</div>
				</div>
				<div class="pageConfigBoxContent">
					<div class="pageConfigBoxContentItem">
						<div class="form_text">开关门</div>
						<div class="form_item">
							<el-switch v-model="doorConfig.doorState" @change="handleSwitchDoor" active-color="#13ce66" inactive-color="#ff4949">
							</el-switch>
						</div>
						<div class="form_hint">提示：开启后方可收到安全终端监控信息的上报</div>
					</div>
					<div class="pageConfigBoxContentItem">
						<div class="form_text">告警阈值</div>
						<div class="form_item_input door_class">
							<el-input v-model="doorConfig.doorFrequency" placeholder="请输入告警阈值" v-validate="'required|pin'"></el-input>
							<wj-Button type="save" v-checksubmit="{ submitEvent: send_door, cls: 'door_class' }">确定</wj-Button>
						</div>
						<div class="form_hint">提示：更频繁的上报频率可以查看更实时的数据，但也会占用网络带宽</div>
					</div>
				</div>
			</div>
			<div class="pageConfigBox">
				<div class="pageConfigBoxTitle">
					<div class="titleText">VPN上报配置</div>
				</div>
				<div class="pageConfigBoxContent">
					<div class="pageConfigBoxContentItem">
						<div class="form_text">VPN上报</div>
						<div class="form_item">
							<el-switch v-model="VPNConfig.VPNState" @change="handleSwitchVPN" active-color="#13ce66" inactive-color="#ff4949">
							</el-switch>
						</div>
						<div class="form_hint">提示：开启后方可收到安全终端监控信息的上报</div>
					</div>
					<div class="pageConfigBoxContentItem">
						<div class="form_text">发送频率</div>
						<div class="form_item">
							<el-select v-model="VPNConfig.VPNFrequency" placeholder="请选择" @change="handleSelect_VPN">
								<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"> </el-option>
							</el-select>
						</div>
						<div class="form_hint">提示：更频繁的上报频率可以查看更实时的数据，但也会占用网络带宽</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</template>
<script>
import {
	system_parameter_all,
	system_parameter_heart,
	system_parameter_request,
	system_parameter_waring,
	system_parameter_waringState,
	system_parameter_audit,
	system_parameter_auditState,
	system_parameter_compare,
	system_parameter_compareState,
	system_parameter_terminalMonitoring,
	system_parameter_terminalMonitoringState,
	system_parameter_systemLog,
	system_parameter_systemLogState,
	system_parameter_door,
	system_parameter_doorState,
	system_parameter_VPN,
	system_parameter_VPNState,
} from "@/utils/request/api";
export default {
	name: "SystemParameter",
	data() {
		return {
			// 下拉数据（下拉时间）
			options: [
				{
					value: "30秒",
					label: "30秒",
				},
				{
					value: "60秒",
					label: "60秒",
				},
				{
					value: "5分钟",
					label: "5分钟",
				},
				{
					value: "10分钟",
					label: "10分钟",
				},
				{
					value: "30分钟",
					label: "30分钟",
				},
				{
					value: "1小时",
					label: "1小时",
				},
				{
					value: "6小时",
					label: "6小时",
				},
				{
					value: "12小时",
					label: "12小时",
				},
				{
					value: "24小时",
					label: "24小时",
				},
			],
			// 心跳配置
			heartbeatConfig: {
				heartbeatFrequency: "",
			},
			// 请求配置
			requestConfig: {
				requestFrequency: "",
			},
			// 告警上报配置
			waringConfig: {
				waringState: false,
				waringFrequency: "",
			},
			// 审计上报配置
			auditConfig: {
				auditState: false,
				auditFrequency: "",
			},
			// 比较上报配置
			compareConfig: {
				compareState: false,
				compareFrequency: "",
			},
			// 终端监控配置
			terminalMonitoringConfig: {
				terminalMonitoringState: false,
				terminalMonitoringFrequency: "",
			},
			// 系统日志配置
			systemLogConfig: {
				systemLogState: false,
				systemLogFrequency: "",
			},
			// 开关门配置
			doorConfig: {
				doorState: false,
				doorFrequency: "",
			},
			// VPN配置
			VPNConfig: {
				VPNState: false,
				VPNFrequency: "",
			},
		};
	},
	create() {},
	mounted() {
		this.getAllParameter();
	},
	methods: {
		// 心跳
		handleSelect_heartbeat() {
			console.log(this.heartbeatConfig.heartbeatFrequency);
			console.log(this.transitionSelectTime(this.heartbeatConfig.heartbeatFrequency));
			system_parameter_heart({
				heart: this.transitionSelectTime(this.heartbeatConfig.heartbeatFrequency),
			}).then((res) => {
				console.log(res);
				if (res.code == 200) {
					this.$msg.success("心跳频率修改成功！");
				} else {
					this.$msg.error("心跳频率修改失败！");
				}
			});
		},
		// 请求
		handleSelect_request() {
			console.log(this.requestConfig.requestFrequency);
			console.log(this.transitionSelectTime(this.requestConfig.requestFrequency));
			system_parameter_request({
				requestFrequency: this.transitionSelectTime(this.requestConfig.requestFrequency),
			}).then((res) => {
				console.log(res);
				if (res.code == 200) {
					this.$msg.success("请求频率修改成功！");
				} else {
					this.$msg.error("请求频率修改失败！");
				}
			});
		},
		// 告警上报
		handleSwitchWaring(newValue) {
			console.log(newValue);
			console.log(this.transitionArgument(newValue));
			system_parameter_waringState({
				warnningStatus: this.transitionArgument(newValue),
			}).then((res) => {
				console.log(res);
				if (res.code == 200) {
					this.$msg.success("告警上报配置成功！");
				} else {
					this.$msg.error("告警上报配置失败！");
				}
			});
		},
		handleSelect_waring() {
			console.log(this.waringConfig.waringFrequency);
			console.log(this.transitionSelectTime(this.waringConfig.waringFrequency));
			system_parameter_waring({
				warningFrequency: this.transitionSelectTime(this.waringConfig.waringFrequency),
			}).then((res) => {
				console.log(res);
				if (res.code == 200) {
					this.$msg.success("告警上报发送频率修改成功！");
				} else {
					this.$msg.error("告警上报发送频率修改失败！");
				}
			});
		},
		// 审计上报
		handleSwitchAudit(newValue) {
			console.log(newValue);
			console.log(this.transitionArgument(newValue));
			system_parameter_auditState({
				auditStatus: this.transitionArgument(newValue),
			}).then((res) => {
				console.log(res);
				if (res.code == 200) {
					this.$msg.success("审计上报配置成功！");
				} else {
					this.$msg.error("审计上报配置失败！");
				}
			});
		},
		handleSelect_audit() {
			console.log(this.auditConfig.auditFrequency);
			console.log(this.transitionSelectTime(this.auditConfig.auditFrequency));
			system_parameter_audit({
				auditFrequency: this.transitionSelectTime(this.auditConfig.auditFrequency),
			}).then((res) => {
				console.log(res);
				if (res.code == 200) {
					this.$msg.success("审计上报发送频率修改成功！");
				} else {
					this.$msg.error("审计上报发送频率修改失败！");
				}
			});
		},
		// 比较上报
		handleSwitchCompare(newValue) {
			console.log(newValue);
			console.log(this.transitionArgument(newValue));
			system_parameter_compareState({
				compareStatus: this.transitionArgument(newValue),
			}).then((res) => {
				console.log(res);
				if (res.code == 200) {
					this.$msg.success("比较上报配置成功！");
				} else {
					this.$msg.error("比较上报配置失败！");
				}
			});
		},
		handleSelect_compare() {
			console.log(this.compareConfig.compareFrequency);
			console.log(this.transitionSelectTime(this.compareConfig.compareFrequency));
			system_parameter_compare({
				compareFrequency: this.transitionSelectTime(this.compareConfig.compareFrequency),
			}).then((res) => {
				console.log(res);
				if (res.code == 200) {
					this.$msg.success("比较上报发送频率修改成功！");
				} else {
					this.$msg.error("比较上报发送频率修改失败！");
				}
			});
		},
		// 终端监控
		handleSwitchTerminalMonitoring(newValue) {
			console.log(newValue);
			console.log(this.transitionArgument(newValue));
			system_parameter_terminalMonitoringState({
				monitoringStatus: this.transitionArgument(newValue),
			}).then((res) => {
				console.log(res);
				if (res.code == 200) {
					this.$msg.success("终端监控配置成功！");
				} else {
					this.$msg.error("终端监控配置失败！");
				}
			});
		},
		handleSelect_terminalMonitoring() {
			console.log(this.terminalMonitoringConfig.terminalMonitoringFrequency);
			console.log(this.transitionSelectTime(this.terminalMonitoringConfig.terminalMonitoringFrequency));
			system_parameter_terminalMonitoring({
				monitorFrequency: this.transitionSelectTime(this.terminalMonitoringConfig.terminalMonitoringFrequency),
			}).then((res) => {
				console.log(res);
				if (res.code == 200) {
					this.$msg.success("终端监控发送频率修改成功！");
				} else {
					this.$msg.error("终端监控发送频率修改失败！");
				}
			});
		},
		// 系统日志
		handleSwitchSystemLog(newValue) {
			console.log(newValue);
			console.log(this.transitionArgument(newValue));
			system_parameter_systemLogState({
				pcsyslogStatus: this.transitionArgument(newValue),
			}).then((res) => {
				console.log(res);
				if (res.code == 200) {
					this.$msg.success("系统日志配置成功！");
				} else {
					this.$msg.error("系统日志配置失败！");
				}
			});
		},
		handleSelect_systemLog() {
			console.log(this.systemLogConfig.systemLogFrequency);
			console.log(this.transitionSelectTime(this.systemLogConfig.systemLogFrequency));
			system_parameter_systemLog({
				pcSyslogFrequency: this.transitionSelectTime(this.systemLogConfig.systemLogFrequency),
			}).then((res) => {
				console.log(res);
				if (res.code == 200) {
					this.$msg.success("系统日志发送频率修改成功！");
				} else {
					this.$msg.error("系统日志发送频率修改失败！");
				}
			});
		},
		// 开关门
		handleSwitchDoor(newValue) {
			console.log(newValue);
			console.log(this.transitionArgument(newValue));
			system_parameter_doorState({
				doorStatus: this.transitionArgument(newValue),
			}).then((res) => {
				console.log(res);
				if (res.code == 200) {
					this.$msg.success("开关门配置成功！");
				} else {
					this.$msg.error("开关门配置失败！");
				}
			});
		},
		send_door() {
			console.log(this.doorConfig.doorFrequency);
			console.log(this.transitionSelectTime(this.doorConfig.doorFrequency));
			system_parameter_door({
				doorFrequency: this.doorConfig.doorFrequency,
			}).then((res) => {
				console.log(res);
				if (res.code == 200) {
					this.$msg.success("开关门告警阈值修改成功！");
				} else {
					this.$msg.error("开关门告警阈值修改失败！");
				}
			});
		},
		// VPN
		handleSwitchVPN(newValue) {
			console.log(newValue);
			console.log(this.transitionArgument(newValue));
			system_parameter_VPNState({
				vpnStatus: this.transitionArgument(newValue),
			}).then((res) => {
				console.log(res);
				if (res.code == 200) {
					this.$msg.success("VPN上报配置成功！");
				} else {
					this.$msg.error("VPN上报配置失败！");
				}
			});
		},
		handleSelect_VPN() {
			console.log(this.VPNConfig.VPNFrequency);
			console.log(this.transitionSelectTime(this.VPNConfig.VPNFrequency));
			system_parameter_VPN({
				vpnFrequency: this.transitionSelectTime(this.VPNConfig.VPNFrequency),
			}).then((res) => {
				console.log(res);
				if (res.code == 200) {
					this.$msg.success("VPN发送频率修改成功！");
				} else {
					this.$msg.error("VPN发送频率修改失败！");
				}
			});
		},
		// 0/1 相互转换 true/false
		transitionArgument(value) {
			var returnValue;
			if (value === 0) {
				returnValue = true;
			} else if (value === 1) {
				returnValue = false;
			} else if (value === true) {
				returnValue = 0;
			} else if (value === false) {
				returnValue = 1;
			}
			return returnValue;
		},
		// 频率时间 相互转换 秒值
		transitionSelectTime(value) {
			var returnValue;
			switch (value) {
				case "30秒":
					returnValue = 30;
					break;
				case "60秒":
					returnValue = 60;
					break;
				case "5分钟":
					returnValue = 300;
					break;
				case "10分钟":
					returnValue = 600;
					break;
				case "30分钟":
					returnValue = 1800;
					break;
				case "1小时":
					returnValue = 3600;
					break;
				case "6小时":
					returnValue = 21600;
					break;
				case "12小时":
					returnValue = 43200;
					break;
				case "24小时":
					returnValue = 86400;
					break;
				case 30:
					returnValue = "30秒";
					break;
				case 60:
					returnValue = "60秒";
					break;
				case 300:
					returnValue = "5分钟";
					break;
				case 600:
					returnValue = "10分钟";
					break;
				case 1800:
					returnValue = "30分钟";
					break;
				case 3600:
					returnValue = "1小时";
					break;
				case 21600:
					returnValue = "6小时";
					break;
				case 43200:
					returnValue = "12小时";
					break;
				case 86400:
					returnValue = "24小时";
					break;
			}
			return returnValue;
		},
		// 查询所有的参数配置
		getAllParameter() {
			system_parameter_all().then((res) => {
				console.log(res);
				if (res.code == 200) {
					this.heartbeatConfig.heartbeatFrequency = this.transitionSelectTime(res.data.heartFrequency);
					this.requestConfig.requestFrequency = this.transitionSelectTime(res.data.requestFrequency);
					this.waringConfig.waringFrequency = this.transitionSelectTime(res.data.warningFrequency);
					this.waringConfig.waringState = this.transitionArgument(res.data.warningStatus);
					this.auditConfig.auditFrequency = this.transitionSelectTime(res.data.auditFrequency);
					this.auditConfig.auditState = this.transitionArgument(res.data.auditStatus);
					this.compareConfig.compareFrequency = this.transitionSelectTime(res.data.compareFrequency);
					this.compareConfig.compareState = this.transitionArgument(res.data.compareStatus);
					this.terminalMonitoringConfig.terminalMonitoringFrequency = this.transitionSelectTime(res.data.monitoringFrequency);
					this.terminalMonitoringConfig.terminalMonitoringState = this.transitionArgument(res.data.monitoringStatus);
					this.systemLogConfig.systemLogFrequency = this.transitionSelectTime(res.data.pcSyslogFrequen);
					this.systemLogConfig.systemLogState = this.transitionArgument(res.data.pcSyslogStatus);
					this.doorConfig.doorFrequency = this.transitionSelectTime(res.data.doorFrequency);
					this.doorConfig.doorState = this.transitionArgument(res.data.doorStatus);
					this.VPNConfig.VPNFrequency = this.transitionSelectTime(res.data.vpnFrequency);
					this.VPNConfig.VPNState = this.transitionArgument(res.data.vpnStatus);
				}
			});
		},
	},
};
</script>
<style lang="less" scoped>
.systemParameterPage {
	width: 100%;
	height: 100%;
	background: #ffffff;
	overflow: hidden;
	.systemParameterPageBox {
		width: 103%;
		height: 100%;
		padding: 12px 20px;
		box-sizing: border-box;
		background: #ffffff;
		overflow-y: scroll;
		.pageConfigBox {
			width: 100%;
			display: flex;
			flex-direction: column;
			justify-content: flex-start;
			align-items: flex-start;
			.pageConfigBoxTitle {
				width: 100%;
				height: 54px;
				border-bottom: 1px solid #eee;
				display: flex;
				flex-direction: row;
				justify-content: flex-start;
				align-items: center;
				.titleText {
					width: 120px;
					line-height: 36px;
					font-size: 16px;
					text-align: center;
					background: #eee;
				}
			}
			.pageConfigBoxContent {
				width: 100%;
				display: flex;
				flex-direction: column;
				justify-content: flex-start;
				align-items: center;
				.pageConfigBoxContentItem {
					width: 90%;
					height: 68px;
					display: flex;
					flex-direction: row;
					justify-content: flex-start;
					align-items: center;
					.form_text {
						width: 66px;
						max-width: 88px;
						font-size: 16px;
					}
					.form_item {
						width: 24%;
						height: 40px;
						font-size: 16px;
						margin: 0 24px;
						display: flex;
						flex-direction: row;
						justify-content: flex-start;
						align-items: center;
						/deep/ .el-select{
							width: 70%;
						}
					}
					.form_item_input{
						width: 24%;
						height: 40px;
						font-size: 16px;
						margin: 0 24px;
						display: flex;
						flex-direction: row;
						justify-content: space-between;
						align-items: center;
						/deep/ .el-input{
							width: 70%;
						}
						[class*="wj-button-"] {
							font-size: 16px;
							padding: 10px 18px;
						}
					}
					.form_hint {
						width: 48%;
						height: 40px;
						margin-left: 18px;
						font-size: 14px;
						color: #363636;
						display: flex;
						flex-direction: row;
						justify-content: flex-start;
						align-items: center;
					}
				}
			}
		}
	}
}
</style>
